//
//  PolygonShape.m
//  WhatATool_
//
//  Created by Sam McNamara on 30/01/2010.
//  Copyright 2010 Sussex Downs College. All rights reserved.
//

#import "PolygonShape.h"


@implementation PolygonShape

@synthesize numberOfSides, minimumNumberOfSides, maximumNumberOfSides;

//Define custom accessor methods
-(void) setNumberOfSides:(int)value
{
	if (value >= minimumNumberOfSides && value <= maximumNumberOfSides)
		numberOfSides = value;
	else
		NSLog(@"Out of bounds, %i is not within range of %i - %i", value, minimumNumberOfSides, maximumNumberOfSides);
	
	//NSLog(@"number of sides is %i", numberOfSides);
}

-(void) setMaximumNumberOfSides:(int)value
{
	if (value <= 12)
		maximumNumberOfSides = value;
	else
		NSLog(@"Out of bounds, maxSides %i is higher than 12", value);
}

-(void) setMinimumNumberOfSides:(int)value
{
	if (value > 2)
		minimumNumberOfSides = value;
	else
		NSLog(@"Out of bounds, minSides %i is lower than 3", value);
}

//Define custom initialisation methods
- (id)initWithSides:(int)sides minSides:(int)min maxSides:(int)max
{	
	[self setMinimumNumberOfSides:min];
	[self setMaximumNumberOfSides:max];
	[self setNumberOfSides:sides];
	return self;
}

-(id)init
{		
	return [self initWithSides:5 minSides:3 maxSides:10];
}

//Define Other Methods
- (float) angleInDegrees
{	
	return (([self numberOfSides] - 2.0f) * 180.0f ) / [self numberOfSides];
}

- (float) angleInRadians
{
	return 0;
}

- (NSString *) name
{
		NSArray *shapes = [[NSArray alloc] initWithObjects: @"Triangle",@"Square",@"Pentagon",@"Hexagon",@"Heptagon",@"Octagon",@"Nonagon",@"Decagon",@"Hendecagon",@"Dodecagon",nil];
		[shapes autorelease];
		return ([self numberOfSides] > 2)?[shapes objectAtIndex:([self numberOfSides] - 3)]:@" lie";
}

/*- (void) description
{
	NSLog(@"Hello, I am a %i-sided polygon (that's a%@ to you), with angles of %f degrees.", [self numberOfSides], [self name], [self angleInDegrees]);
}
*/

- (void) dealloc
{
	NSLog(@"Polygon instance (of type %@) has been deallocated.", [self name]);
	[super dealloc];
}




@end
